package com.ophiux.common.log.config;

import com.ophiux.common.core.utils.KeyStrResolver;
import com.ophiux.common.log.aspect.SysLogAspect;
import com.ophiux.common.log.event.SysLogListener;
import com.ophiux.system.api.feign.SysLogFeignApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @desc: 日志自动配置
 * @author: hhl
 * @date：2022/7/19 16:22
 */
@EnableAsync
@Configuration
@ConditionalOnWebApplication
@EnableConfigurationProperties(LogProperties.class)
@ConditionalOnProperty(value = "security.log.enabled", matchIfMissing = true)
public class LogAutoConfiguration {

	@Autowired
	SysLogFeignApi sysLogFeignApi;

	@Bean
	public SysLogListener sysLogListener(LogProperties logProperties) {
 		return new SysLogListener(sysLogFeignApi,logProperties);
	}

	@Bean
	public SysLogAspect sysLogAspect(KeyStrResolver resolver) {
		return new SysLogAspect(resolver);
	}

}
